package com.erification.web.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.erification.web.dao.GroupDao;
import com.erification.web.model.Group;
@Transactional @Repository("groupDao")
public class GroupDapImpl implements GroupDao {
	@Resource
	private SessionFactory sessionFactory;
	
	@Override
	public void save(Group group) {
		sessionFactory.getCurrentSession().save(group);
	}

	@Override
	public void update(Group group) {
		sessionFactory.getCurrentSession().update(group);
	}

	@Override
	public void delete(long id) {
		sessionFactory.getCurrentSession().delete(
				sessionFactory.getCurrentSession().get(Group.class, id));
	}

	@Override @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Group> getAll(long user_id) {
		String queryString = "From Group where user_id = :user_id";
		Query query = sessionFactory.getCurrentSession().createQuery(queryString);
		query.setLong("user_id", user_id);
		return query.list();
	}

	@Override @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Group get(long id) {
		return (Group) sessionFactory.getCurrentSession().get(Group.class, id);
	}
	
	
	

}
